# Contributor: Henrik Riomar <henrik.riomar@gmail.com>
# Maintainer: Henrik Riomar <henrik.riomar@gmail.com>
pkgname=py3-tpm2-pytss
_pkgname=tpm2-pytss
pkgver=2.2.1
pkgrel=0
pkgdesc="Python bindings for TSS"
url="https://github.com/tpm2-software/tpm2-pytss"
arch="all !armhf !armv7 !riscv64 !x86" # limited by failing check()
license="BSD-2-Clause"
checkdepends="
	py3-pytest-forked
	py3-pytest-xdist
	swtpm
	"
makedepends="
	py3-gpep517
	py3-pkgconfig
	py3-setuptools
	py3-setuptools_scm
	py3-wheel
	python3-dev
	tpm2-tss-dev
	"
depends="
	py3-asn1crypto
	py3-cparser
	py3-cryptography
	py3-yaml
	python3
	"
subpackages="$pkgname-pyc"
source="https://github.com/tpm2-software/tpm2-pytss/archive/$pkgver/$_pkgname-$pkgver.tar.gz"
builddir="$srcdir/$_pkgname-$pkgver"

case "$CARCH" in
	armv7|ppc64le|s390x) options="!check";; # no swtpm package
	*) ;;
esac

build() {
	export SETUPTOOLS_SCM_PRETEND_VERSION=$pkgver
	gpep517 build-wheel \
		--wheel-dir .dist \
		--output-fd 3 3>&1 >&2
}

check() {
	python3 -m venv --clear --without-pip --system-site-packages .testenv
	.testenv/bin/python3 -m installer .dist/*.whl
	PYTHONPATH="$(echo .testenv/lib/python3*/site-packages/):$PWD" \
		.testenv/bin/python3 -m pytest test \
		-n"$(nproc)"
}

package() {
	export SETUPTOOLS_SCM_PRETEND_VERSION=$pkgver
	python3 -m installer -d "$pkgdir" \
		.dist/*.whl
}

sha512sums="
b55c8f0ba03204e803e33da115961893a1a7e08bcac29399a728d9f984be2d538076fa7dd289e96beedb6d6125a53f5b5841dd216f89d55833db9eb9197ba747  tpm2-pytss-2.2.1.tar.gz
"
